<!-- 联华商学院 -->
<template>
  <div class="college">
    <header
      v-if="Back.business_back"
      :style="'background: url(' + Back.business_back + ') no-repeat 50% 50%;'"
    >
      <span>{{ i18n.college.college }}</span>
    </header>
    <main>
      <div
        class="list"
        v-for="val in list"
        :key="val.id"
        @click="$method.skip('/college_detail?id='+val.id)"
      >
        <span><img :src="val.image" /></span>
        <p>
          <b>{{ val.title }}</b>
          <span
            ><i>{{ val.abstract }}</i></span
          >
        </p>
      </div>
    </main>
    <el-pagination
      class="pagination"
      :small="width <= 768"
      background
      layout="prev, pager, next"
      :total="count"
      :page-size="from.page_size"
      @current-change="change"
    >
    </el-pagination>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import bus from "@/config/emit";

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      Back: {},
      count: 0,
      list: [],
      from: {
        cid: 5,
        page_no: 1,
        page_size: 10,
      },
    };
  },
  props: ["width"],
  //计算属性 类似于data概念
  computed: {
    i18n() {
      return this.$t("message");
    },
  },
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    change(e) {
      this.from.page_no = e;
      this.getArticle();
    },
    getArticle() {
      this.$getRequest("/index/getArticle", this.from).then((res) => {
        this.list = res.data.lists;
        this.count = res.data.count;
      });
    },
    getBack() {
      this.$getRequest("/index/getBack").then((res) => {
        this.Back = res.data;
      });
    },
  },
  beforeCreate() {}, //生命周期 - 创建之前
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getBack();
    this.getArticle();
    bus.$on("lang", () => {
      if (this.$route.name == "/college") {
        this.getArticle();
      }
    });
  },
  beforeMount() {}, //生命周期 - 挂载之前
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.getArticle();
  }, //如果页面有keep-alive缓存功能，激活
  deactivated() {}, //如果页面有keep-alive缓存功能，非激活
};
</script>
<style lang="less">
.college {
  & > main {
    width: 17.5rem;
    margin: 0.875rem auto;
    padding: 1px 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;

    & > .list:hover {
      transform: scale(1.05);
      box-shadow: 0px 0px 20px 0px #33333330;
    }

    & > .list {
      width: 8.625rem;
      height: 3.5rem;
      background-color: #fff;
      margin-bottom: 0.5rem;
      padding: 0.25rem;
      box-sizing: border-box;
      display: flex;
      transition: all 0.3s;

      & > p {
        flex: 1;
        display: flex;
        flex-direction: column;

        & > span {
          color: #999999;
          font-size: 0.25rem;
          flex: 1;
          display: flex;
          align-items: center;

          & > i {
            overflow: hidden;
            word-break: break-all;
            text-overflow: ellipsis;
            display: -webkit-box !important;
            -webkit-line-clamp: 4;
            -webkit-box-orient: vertical;
          }
        }

        & > b {
          width: 100%;
          padding: 0.15rem;
          text-align: center;
          font-size: 0.3125rem;
          overflow: hidden;
          word-break: break-all;
          text-overflow: ellipsis;
          display: -webkit-box !important;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }

      & > span {
        width: 3.5rem;
        height: 3rem;
        position: relative;
        overflow: hidden;
        margin-right: 0.2875rem;

        & > img {
          min-width: 100%;
          min-height: 3rem;
          height: 3rem;
          position: absolute;
          left: 50%;
          top: 50%;
          transform: translate(-50%, -50%);
        }
      }
    }
  }

  & > .pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
  }

  & > header {
    width: 100%;
    height: 7.5rem;
    background-size: 100% 100% !important;
    color: #fff;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
  }
}

@media screen and (max-width: 768px) {
  .college {
    & > main {
      width: 33.5rem;
      margin: 1rem auto;

      & > .list {
        width: 100%;
        height: 10rem;
        margin-bottom: 1rem;
        padding: 1rem;

        & > p {
          & > span {
            font-size: 1rem;
          }

          & > b {
            padding: 0.3rem 0;
            font-size: 1.2rem;
          }
        }

        & > span {
          width: 10rem;
          height: 8rem;
          margin-right: 1rem;

          & > img {
            min-height: 8rem;
            height: 8rem;
          }
        }
      }
    }

    & > header {
      height: 20rem;
      background-size: auto 100% !important;
      font-size: 1.5rem;
    }
  }
}
</style>